package com.memoir.jpa.controller;

import com.memoir.jpa.model.TodoDto;
import com.memoir.jpa.service.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/todo")
@RestController
public class TodoController {

    @Autowired
    private TodoService todoService;

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public List<TodoDto> getTodosByTitle(@RequestParam(value = "title",required = false) String title){
        return todoService.getTodosByTitle(title);
    }

    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public List<TodoDto> findTodosByTitle(@RequestParam(value = "title",required = false) String title){
        return todoService.findTodosByTitle(title);
    }

    @RequestMapping(value = "/read", method = RequestMethod.GET)
    public List<TodoDto> readTodosByTitle(@RequestParam(value = "title",required = false) String title){
        return todoService.findTodosByTitle(title);
    }

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public int updateTodo(){
        return todoService.updateTodoTitle();
    }
    @RequestMapping(value = "/custom/{id}", method = RequestMethod.GET)
    public TodoDto custom(@PathVariable("id") Integer id){
        return todoService.custom(id);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public TodoDto save(@RequestBody TodoDto todoDto) {
        return todoService.save(todoDto);
    }


}
